#region netDxf, Copyright(C) 2013 Daniel Carvajal, Licensed under LGPL.
// netDxf library
// Copyright (C) 2013 Daniel Carvajal (haplokuon@gmail.com)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#endregion
using System;
namespace netDxf.Entities
{
///
/// Represents a ray entity.
///
/// A ray is a line in three-dimensional space that starts in the specified origin and extends to infinity.
public class Ray :
EntityObject
{
#region private fields
private Vector3 origin;
private Vector3 direction;
#endregion
#region constructors
///
/// Initializes a new instance of the Ray class.
///
public Ray()
: this(Vector3.Zero, Vector3.UnitX)
{
}
///
/// Initializes a new instance of the Ray class.
///
/// Ray start point.
/// Ray end point.
public Ray(Vector2 origin, Vector2 direction)
: this(new Vector3(origin.X, origin.Y, 0.0), new Vector3(direction.X, direction.Y, 0.0))
{
}
///
/// Initializes a new instance of the Ray class.
///
/// Ray start point.
/// Ray end point.
public Ray(Vector3 origin, Vector3 direction)
: base(EntityType.Ray, DxfObjectCode.Ray)
{
this.origin = origin;
this.direction = direction;
this.direction.Normalize();
}
#endregion
#region public properties
///
/// Gets or sets the ray origin.
///
public Vector3 Origin
{
get { return this.origin; }
set { this.origin = value; }
}
///
/// Gets or sets the ray direction.
///
public Vector3 Direction
{
get { return this.direction; }
set
{
if (value == Vector3.Zero)
throw new ArgumentNullException("value", "The direction can not be the zero vector.");
this.direction = value;
this.direction.Normalize();
}
}
#endregion
#region overrides
///
/// Creates a new Ray that is a copy of the current instance.
///
/// A new Ray that is a copy of this instance.
public override object Clone()
{
return new Ray
{
//EntityObject properties
Color = this.color,
Layer = this.layer,
LineType = this.lineType,
Lineweight = this.lineweight,
LineTypeScale = this.lineTypeScale,
Normal = this.normal,
XData = this.xData,
//Ray properties
Origin = this.origin,
Direction = this.direction,
};
}
#endregion
}
}